package com.Txunda.fxw.ui.activity.login;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.Txunda.fxw.R;
import com.Txunda.fxw.base.utils.util.JSONUtils;
import com.Txunda.fxw.base.utils.util.MapUtils;
import com.Txunda.fxw.ui.base.BaseAty;
import com.Txunda.fxw.ui.http.Member;
import com.Txunda.fxw.ui.toolkit.text.CodeCountDown;

import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 创建时间：2018/11/15 16:26
 * 作    者：Hzj
 * 描    述：忘记密码
 * 注    意：
 * 修    改：
 * 参    考：
 * 出    自：书山府科技 android
 **/
public class PwdBackAty extends BaseAty {

    @BindView(R.id.title_center_title)
    TextView titleCenterTitle;
    @BindView(R.id.input_phone_tv)
    EditText inputPhoneTv;
    @BindView(R.id.input_code_tv)
    EditText inputCodeTv;
    @BindView(R.id.get_code_tv)
    TextView getCodeTv;
    @BindView(R.id.input_pwd_tv)
    EditText inputPwdTv;
    @BindView(R.id.input_re_pwd_tv)
    EditText inputRePwdTv;
    @BindView(R.id.be_over_bt)
    Button beOverBt;

    private Member member;

    private CodeCountDown codeCountDown;

    private String phone = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_pwd_back;
    }

    @Override
    protected void initialized() {
        member = new Member();
        codeCountDown = new CodeCountDown(60000, 1000, getCodeTv);
    }

    @Override
    protected void requestData() {

    }

    @Override
    @OnClick({R.id.get_code_tv, R.id.be_over_bt})
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.get_code_tv:// 获取验证码
                String type = "reset";
                phone = inputPhoneTv.getText().toString();
                member.sendVerify(phone, type, this);
                break;
            case R.id.be_over_bt:
                String verify = inputCodeTv.getText().toString();
                String pwd1 = inputPwdTv.getText().toString();
                String pwd2 = inputRePwdTv.getText().toString();
                member.resetPassword(phone, verify, pwd1, pwd2, this);
                break;
        }
    }

    @Override
    public void onComplete(String requestUrl, String jsonStr) {
        super.onComplete(requestUrl, jsonStr);
        if (requestUrl.contains("/Api/Member/sendVerify")) {
            showTips(R.drawable.icon_right_tip, "信息已送达");
            if (codeCountDown != null)
                codeCountDown.start();
            return;
        }
        if (requestUrl.contains("/Api/Member/resetPassword")) {
            showTips(R.drawable.icon_right_tip, "找回密码成功");
            finish();
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (isFinishing() && codeCountDown != null)
            codeCountDown.cancel();
    }
}
